from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.workflows import router as workflows_router
from app.api.nodes import router as nodes_router  # 新增
from app.db import init_db

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["http://localhost:8080"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(workflows_router, prefix="/api")
app.include_router(nodes_router, prefix="/api")  # 新增

@app.on_event("startup")
async def startup_event():
    init_db()